<%@page import="com.project.vo.Picture"%>
<%@page import="java.util.List"%>
<%@page import="com.project.vo.Product"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%
	Product product = (Product) request.getAttribute(StringUtil.PRODUCT);
	List<Picture> pictures = (List<Picture>) request.getAttribute(StringUtil.PICTURES);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<%@ include file="/WEB-INF/jsp/include/head.jsp"%>
<title>修改服装信息</title>
</head>
<body>
	<%@ include file="/WEB-INF/jsp/include/admin/top.jsp"%>
	<%@ include file="/WEB-INF/jsp/include/admin/left.jsp"%>
	<div class="main col-lg-9 col-md-9 col-xs-12 col-sm-12">
		<form action="admin/product/update" method="post"
			enctype="multipart/form-data">
			<input type="hidden" name="id" value="<%=product.getId()%>" >
			<table class="table col-lg-12 col-md-12 col-xs-12 col-sm-12">
				<tr>
					<th><%=StringUtil.P_ID%>:</th>
					<td><%=product.getId()%></td>
				</tr>
				<tr>
					<th><%=StringUtil.P_NAME%>:</th>
					<td><input type="text" name="name"
						value="<%=product.getName()%>"
						placeholder="<%=StringUtil.P_NAME%>"></td>
				</tr>
				<tr>
					<th><%=StringUtil.P_DESCRIPTION%>:</th>
					<td><input type="text" name="description"
						value="<%=product.getDescription()%>"
						placeholder="<%=StringUtil.P_DESCRIPTION%>"></td>
				</tr>
				<tr>
					<th><%=StringUtil.P_PRICE%>:</th>
					<td><input type="text" name="price"
						value="<%=product.getPrice()%>"
						placeholder="<%=StringUtil.P_PRICE%>"></td>
				</tr>
				<tr>
					<th><%=StringUtil.P_NUM%>:</th>
					<td><input type="text" name="num"
						value=<%=product.getNum()%> placeholder="<%=StringUtil.P_NUM%>"></td>
				</tr>
				<tr>
					<th><%=StringUtil.P_KIND_ID %>:</th>
					<td><input type="text" name="kind_id"
						value="<%=product.getKind_id() %>" placeholder="<%=StringUtil.P_KIND_ID %>"></td>
				</tr>
				<tr>
					<th><%=StringUtil.P_URL%>:</th>
					<td><input type="text" name="url"
						value="<%=product.getUrl()%>" placeholder="<%=StringUtil.P_URL%>"></td>
				</tr>
				<%
					String clientBasePath = StringUtil.CLIENTBASEPATH; //前端的根路径
				%>
				<tr id="imagetr" class="imagetr">
					<th>图片:</th>
					<%
						for (Picture picture : pictures) {
					%>
					<td><img alt="<%=StringUtil.IMGALT%>"
						src="<%=clientBasePath%>/<%=picture.getPath()%>"
						picId="<%=picture.getId()%>" class="picture" style="height: 100px; width:120px"> <label
						id="delete" class="btn delete"><strong>X</strong></label></td>
					<%
						}
					%>
					<td>
						<label id="edit_add_image" class="btn im_oper">添加</label>
						<label id="edit_delete_image" class="btn im_oper">删除</label>
<%-- 						<img src="<%=basePath%>/resources/images/add.gif"id="edit_add_image" class="im_oper"></img>  --%>
<%-- 						<img src="<%=basePath%>/resources/images/delete.png" id="edit_delete_image" class="im_oper"></img></td> --%>
				</tr>
				<tr>
					<td><input type="submit" class="btn" value="确认修改"></td>
					<td><input type="reset" class="btn" value="重新填写"></td>
				</tr>
			</table>

		</form>
	</div>
	<%@ include file="/WEB-INF/jsp/include/bottom.jsp"%>
</body>
<script type="text/javascript">
	$pictures = $(".delete");
	$pictures.click(function() {
				var id = $(this).prev().attr("picId");
				var $parent = $(this).parent();
				var url = "http://localhost:8080/imageretrival/ajax/imageDelete?picture_id="+ id;
				$.ajax({
					url : url,
					type : "POST",
					data : {},
					contentType : "application/json",
					dataType : "json",
					cache : false,
					success : function(data) {
						var d = eval("(" + data + ")");//将数据转换成json类型
						if (d.result == "success") {
							alert("删除成功!");
							$parent.remove();
						} else {
							alert("删除失败!");
						}
					},
					error : function(data) {
						alert(data.responseText);
					}
				});
			});
</script>
</html>